package megrez.oss.minio.web.vo;

import java.time.ZonedDateTime;
import java.util.Map;

import io.minio.StatObjectResponse;
import lombok.Data;

/**
 * <code>io.minio.StatObjectResponse</code> 包装实体类
 *  
 * @author Lucky Yang
 * @since 2.6.9
 */
@Data
public class StatObjectResponseVO {
    private String etag;
    private long size;
    private ZonedDateTime lastModified;
    private String retentionMode;
    private ZonedDateTime retentionRetainUntilDate;
    private boolean legalHold;
    private boolean deleteMarker;
    private String versionId;
    private String contentType;
    private String bucket;
    private String object;
    private Map<String, String> userMetadata;

    public static StatObjectResponseVO of(StatObjectResponse stat) {
        StatObjectResponseVO rslt = new StatObjectResponseVO();

        rslt.setContentType(stat.contentType());
        rslt.setDeleteMarker(stat.deleteMarker());
        rslt.setEtag(stat.etag());
        rslt.setLastModified(stat.lastModified());
        rslt.setLegalHold(stat.legalHold() != null ? stat.legalHold().status() : null);
        rslt.setRetentionMode(stat.retentionMode() != null ? stat.retentionMode().name() : null);
        rslt.setRetentionRetainUntilDate(stat.retentionRetainUntilDate());
        rslt.setSize(stat.size());
        rslt.setUserMetadata(stat.userMetadata());
        rslt.setVersionId(stat.versionId());
        rslt.setBucket(stat.bucket());
        rslt.setObject(stat.object());
        return rslt;
    }
}
